const express = require("express");
const app = express();
const hero = require("./routes/hero");
const user = require("./routes/user");
const jwt = require('express-jwt');

// 接受post请求的参数
app.use(express.urlencoded());

// 文件静态托管
app.use("", express.static("uploads"));

// 使用中间件来验证 token 

// secret 钥匙
// HS256 加密的算法 
// unless 哪些接口不需要 验证token
app.use(jwt({ secret: 'node66', algorithms: ['HS256'] }).unless({ path: ['/user/login', '/user/register'] }));

app.use("/hero", hero);
app.use("/user", user);

app.listen(8001, () => {
  console.log("8001 端口开启成功");
});